#######################################
## Specificity & Sensitivity analysis
#######################################
## Dependents on objects generated by 
## GenErrorTestSet.R

preds <- (errors.one[[1]][["bart.res"]][["1"]][["bartres"]][["yhat.test.mean"]])
length((errors.one[[1]][["bart.res"]][["1"]][["bartres"]][["yhat.test.mean"]]))
length((errors.one[[1]][["bart.res"]][["1"]][["bartres"]][["yhat.tran.mean"]]))
dim(errors.one[[1]][["bart.res"]][["1"]][["train.x"]])[1]/598
dim(errors.one[[1]][["bart.res"]][["1"]][["test.x"]])[1]/598

out <- (errors.one[[1]][["bart.res"]][["1"]][["y.test"]])
plot(out~preds)
abline(lm(out~preds))


median(preds)
bipreds <- (preds>0)*1
table(bipreds)

table(out, bipreds)/colSums(table(out, bipreds))
table(bipreds)/sum(table(bipreds))

biout <- (out>0)*1
table(biout)/sum(table(biout))
table(biout, bipreds)
table(biout, bipreds)/rowSums(table(biout, bipreds))
table(biout)
print(table(biout, bipreds)/sum(table(biout, bipreds)))[2,2]/((table(biout, bipreds)/sum(table(biout, bipreds)))[2,2]+(table(biout, bipreds)/sum(table(biout, bipreds)))[1,2])

